package com.baihan.angus.app.game.busshow;

import android.content.Context;

import androidx.annotation.NonNull;

import com.baihan.angus.app.game.basic.BaseApplication;
import com.baihan.angus.app.game.basic.configs.BasicConfig;
import com.baihan.angus.app.game.basic.utils.AppLanguageUtil;
import com.baihan.angus.app.game.common.configs.UserConfig;
import com.baihan.angus.app.game.common.widgets.SmartRefreshHeader;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshFooter;
import com.scwang.smart.refresh.layout.api.RefreshHeader;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator;
import com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;

public class BusShowApp extends BaseApplication {

    @Override
    public String getAppServerToken() {
        return UserConfig.getUserConfig().getSavedAppToken();
    }

    /**
     * 此方法先于 onCreate()方法执行
     *
     * @param newBase
     */
    @Override
    protected void attachBaseContext(Context newBase) {
        BasicConfig.initSP(newBase);
        //获取我们存储的语言环境 比如 "en","zh",等等
        int languageCode = BasicConfig.getInstance().getLanguageCode();
        /**
         * attach对应语言环境下的context
         */
        super.attachBaseContext(AppLanguageUtil.attachBaseContext(newBase, languageCode));
    }

    @Override
    public void onCreate() {
        super.onCreate();
        ZXingLibrary.initDisplayOpinion(this);

        /**
         * 对于7.0以下，需要在Application创建的时候进行语言切换
         * 现在不支持8.0以下
         */
//        int language = BasicConfigSP.getLauguageCode();
//        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
//            AppLanguageUtil.changeAppLanguage(this, language);
//        } else {
//            AppLanguageUtil.updateApplicationConfiguration(language);
//        }
    }


    static {
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                return new SmartRefreshHeader(context);
            }
        });

        SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
            @NonNull
            @Override
            public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout) {
                layout.setPrimaryColorsId(android.R.color.transparent, R.color.textColor1);//全局设置主题颜色
                return new ClassicsFooter(context);
            }
        });
    }
}
